# File Name:  CR_Figure2.R
# Data:       CRdata_jpp_final.dta
# Purpose:    Plot net change in policy scores.


library(readstata13)

x<-read.dta13(file="C:/Users/MDR/Dropbox/Vanderbilt/Fall 2013/Project/Charter/ClintonRichardson Draft/jpp_replication/CRdata_jpp_final.dta",
              convert.factors=F)

#Figure 2 - net change in policy scores

st<-unique(x$state)

pdf(file="C:/Users/MDR/Dropbox/Vanderbilt/Fall 2013/Project/Charter/ClintonRichardson Draft/Figures/firstVlast.pdf",height=14,width=14)

par(mfrow=c(2,2),mar=c(7,6,2,2),cex.axis=1.5,cex.lab=1.2,las=1,cex.main=2)

#Policy Liberalism
plot(x$policy_score[x$cw_session==1],x$policy_score[x$cw_session==11],xlab="Period 1\n(1993 & 1994)", ylab="Period 11\n(2013 & 2014)",
     main="State Policy Liberalism",xlim=c(-2.5,2.5),ylim=c(-2.5,2.5),type="n")
for(i in 1:length(st)){#use a loop to be sure states are matched correctly
  text(x$policy_score[x$cw_session==1&x$state==st[i]&is.na(x$cw_session)==F],
       x$policy_score[x$cw_session==11&x$state==st[i]&is.na(x$cw_session)==F], st[i],cex=1.4)
}
abline(a=0,b=1)

#empty plot
plot(1,1,type="n",xaxt="n",yaxt="n",xlab="",ylab="",bty="n")

#Abortion policy
x$abortion_score[x$state=="LA"&x$ab_session==1&is.na(x$ab_session)==F]<-x$abortion_score[x$state=="LA"&x$ab_session==2&is.na(x$ab_session)==F]
x$abortion_score[x$state=="MS"&x$ab_session==1&is.na(x$ab_session)==F]<-x$abortion_score[x$state=="MS"&x$ab_session==2&is.na(x$ab_session)==F]
x$abortion_score[x$state=="NJ"&x$ab_session==1&is.na(x$ab_session)==F]<-x$abortion_score[x$state=="NJ"&x$ab_session==2&is.na(x$ab_session)==F]
x$abortion_score[x$state=="VA"&x$ab_session==1&is.na(x$ab_session)==F]<-x$abortion_score[x$state=="VA"&x$ab_session==2&is.na(x$ab_session)==F]

plot(jitter(x$abortion_score[x$ab_session==1]),jitter(x$abortion_score[x$ab_session==6]),
     xlab="Period 1\n(2004 & 2005)",ylab="Period 6\n(2013 & 2014)",main="Abortion Policy",
     xlim=c(0,12),ylim=c(0,12),type="n")
for(i in 1:length(st)){
text(jitter(x$abortion_score[x$ab_session==1&x$state==st[i]&is.na(x$ab_session)==F&is.na(x$ab_session)==F]),
     jitter(x$abortion_score[x$ab_session==6&x$state==st[i]&is.na(x$ab_session)==F&is.na(x$ab_session)==F]),
     st[i],cex=1.4)
}
abline(a=0,b=1)

#Charter school policy
plot(jitter(x$comp_score_coded[x$ch_session==1&is.na(x$comp_score_coded)==F]),
     jitter(x$comp_score_coded[x$ch_session==9&is.na(x$comp_score_coded)==F]),xlab="Period 1\n(1997 & 1998)",
     ylab="Period 9\n(2013 & 2014)",main="Charter School Policy",xlim=c(0,1),ylim=c(0,1),type="n")
for(i in 1:length(st)){
text(jitter(x$comp_score_coded[x$ch_session==1&x$state==st[i]&is.na(x$ch_session)==F]),
     jitter(x$comp_score_coded[x$ch_session==9&x$state==st[i]&is.na(x$ch_session)==F]),
     st[i],cex=1.4)
}
abline(a=0,b=1)

dev.off()
